#ifndef CITY_H
#define CITY_H

#include "AReVi/arObject.h"
using namespace AReVi;

#include "building.h"

class Square : public ArObject{
public:
  AR_CLASS(Square)
  AR_CONSTRUCTOR(Square)
  AR_CONSTRUCTOR_4(Square, double, posX,
                           double, posY,
                           double, sizeX,
                           double, sizeY)


  pair<ArRef<Square>, ArRef<Square> >
  divide(double widthBetween, double minWidth);

  double pos[2];
  double size[2];
};

//----------------------------------------------------------------------------

class City : public Element
{
public:
  AR_CLASS(City)
  AR_CONSTRUCTOR(City)

  bool
  buildCity(double sizeX,
            double sizeY,
            double maxSlenderness,
            double roadWidth,
            double sideWalkwidth,
            double buildingMinWidth,
            unsigned int nbBuildings);

  const StlVector<ArRef<Element> >&
  getBuildings(void);

  ArRef<Object3D>
  getRoad(void);

  /** 3D Representation handling */
  inline virtual ArRef<Object3D> getRepresentation(void) const { return _road; }

  /** Initialise element. Must be done after calling constructor.
    *  Can be used to differenciate local and distant elements */
  virtual void init();

protected:
  /** Write Element configuration to stream */
  virtual void writeConfiguration(ArRef<AbstractOStream> oStream);
  /** Read Element configuration to stream */
  virtual void readConfiguration(ArRef<AbstractIStream> iStream);

  /** Write Element configuration to stream */
  virtual void writeUpdate(ArRef<AbstractOStream> oStream);
  /** Read Element configuration to stream */
  virtual void readUpdate(ArRef<AbstractIStream> iStream);


  void
  _computeBuildings(StlVector<ArRef<Square> > squares, 
                    double maxSlenderness,
                    double sideWalkWidth);

  StlVector<ArRef<Element> > _buildings;

  ArRef<Object3D> _road;

  double _sizeX;
  double _sizeY;
};



#endif
